package com.awspaas.user.apps.cpq.controller;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.actionsoft.bpms.bo.engine.BO;
import com.actionsoft.bpms.commons.database.RowMap;
import com.actionsoft.bpms.commons.mvc.view.ResponseObject;
import com.actionsoft.bpms.server.UserContext;
import com.actionsoft.bpms.util.DBSql;
import com.actionsoft.sdk.local.SDK;

public class CPQ_GetPriceMsgWLWeb {

	public String getPriceMsgWL(UserContext userContext, String bindId, String datas) {
		try {
			List<BO> bos=SDK.getBOAPI().query("BO_EU_CPQ_COMPONENT_PART_GRID").bindId(bindId).list();
			if(bos.size()>0) {
				String bms = "";
				for (BO bo : bos) {
					String bm=	bo.getString("BM");
					if (bms.isEmpty()) {
						bms = "'" + bm + "'";
					} else {
						bms += ",'" + bm + "'";
					}
				}
				String sql="select  BM,NAME,TYPE,GG,TH,DW,ZL,TJ,CLF,RGF,WXWG,CGF,DJ from  BO_EU_CPQ_COMPONENT_PART where BM  in("+bms+")";
				List<RowMap> maps=DBSql.getMaps(sql);
				Map<String,RowMap> wlmap=new HashMap<String, RowMap>();
				if(maps.size()>0) {
					for (RowMap rowMap : maps) {
						wlmap.put(rowMap.getString("BM"), rowMap);
					}
				}
					for (BO bo : bos) {
						String bm=	bo.getString("BM");
						if(wlmap.containsKey(bm)) {
							RowMap map=wlmap.get(bm);
							String SL=bo.getString("SL").isEmpty()?"0":bo.getString("SL");
							BigDecimal sl=new BigDecimal(SL);	
							String newdj=map.getString("DJ").isEmpty()?"0":map.getString("DJ");	
							bo.set("DJ", newdj);
							BigDecimal djNew=new BigDecimal(newdj);	
							BigDecimal zj=djNew.multiply(sl);
							bo.set("ZJ", zj);
							String newclf=map.getString("CLF").isEmpty()?"0":map.getString("CLF");	
							bo.set("CLF", newclf);
							BigDecimal clfNew=new BigDecimal(newclf);	
							BigDecimal zclf=clfNew.multiply(sl);
							bo.set("ZCLF", zclf);
							String newrg=map.getString("RGF").isEmpty()?"0":map.getString("RGF");	
							bo.set("RGF", newrg);
							BigDecimal rgNew=new BigDecimal(newrg);	
							BigDecimal zrg=rgNew.multiply(sl);
							bo.set("ZGSF", zrg);
							String newwx=map.getString("WXWG").isEmpty()?"0":map.getString("WXWG");	
							bo.set("WXWG", newwx);
							BigDecimal wxNew=new BigDecimal(newwx);	
							BigDecimal zwx=wxNew.multiply(sl);
							bo.set("ZWX", zwx);
							String newcgf=map.getString("CGF").isEmpty()?"0":map.getString("CGF");	
							bo.set("CGF", newcgf);
							BigDecimal cgfNew=new BigDecimal(newcgf);	
							BigDecimal zcgf=cgfNew.multiply(sl);
							bo.set("ZCGF", zcgf);
							String newzl=map.getString("ZL").isEmpty()?"0":map.getString("ZL");	
							bo.set("ZL", newzl);
							BigDecimal zlNew=new BigDecimal(newzl);	
							BigDecimal zzl=zlNew.multiply(sl);
							bo.set("ZZL", zzl);
							String newtj=map.getString("TJ").isEmpty()?"0":map.getString("TJ");	
							bo.set("TJ", newtj);
							BigDecimal tjNew=new BigDecimal(newtj);	
							BigDecimal ztj=tjNew.multiply(sl);
							bo.set("ZTJ", ztj);
							bo.set("MC", map.getString("NAME"));
							bo.set("LX", map.getString("TYPE"));
							bo.set("GG", map.getString("GG"));
							bo.set("DH", map.getString("TH"));
							bo.set("DW", map.getString("DW"));
							SDK.getBOAPI().update("BO_EU_CPQ_COMPONENT_PART_GRID", bo);
						}
					}
			}
			   ResponseObject ro = ResponseObject.newOkResponse();
				return ro.toString();
		} catch (Exception e) {
			throw e;
		}
		
	}

}
